<script setup>
import { RouterView, RouterLink } from 'vue-router'
import { useUserStore } from './stores/user'
import Footer from './components/common/Footer.vue'
import { useRoute } from 'vue-router'
import Notice from './components/common/Notice.vue'

// 引入用户状态，用于根据登录状态和角色显示不同的导航链接
const userStore = useUserStore()
const route = useRoute()
</script>

<template>
  <div class="app-container">
    <!-- 简单的顶部导航栏，仅在非登录/注册页面显示 -->
    <header v-if="$route.path !== '/login' && $route.path !== '/register' && $route.path !== '/statistician/health-data-dashboard'" class="main-header">
      <nav class="nav-container">
        <div class="logo">健康预测系统</div>
        <div class="nav-links">
          <!-- 未登录状态 -->
          <template v-if="!userStore.isLoggedIn">
            <RouterLink to="/login" class="nav-link">登录</RouterLink>
            <RouterLink to="/register" class="nav-link">注册</RouterLink>
          </template>
          <!-- 已登录状态 - 根据角色显示不同的导航选项 -->
          <template v-else>
            <!-- 用户导航 -->
            <template v-if="userStore.role === 'user'">
              <RouterLink to="/user/dashboard" class="nav-link">首页</RouterLink>
              <RouterLink to="/user/system-feedback" class="nav-link">系统反馈</RouterLink>
            </template>
            <!-- 统计员导航 - 按要求顺序排列 -->
            <template v-else-if="userStore.role === 'statistician'">
              <RouterLink to="/statistician/health-data-dashboard" class="nav-link">健康数据可视化大屏</RouterLink>
              <RouterLink to="/statistician/data-export" class="nav-link">系统反馈</RouterLink>
              <RouterLink to="/statistician/profile" class="nav-link">个人信息</RouterLink>
            </template>
            <!-- 管理员导航 -->
            <template v-else-if="userStore.role === 'admin'">
              <RouterLink to="/admin/dashboard" class="nav-link">管理面板</RouterLink>
              <RouterLink to="/admin/user-management" class="nav-link">用户管理</RouterLink>
              <RouterLink to="/admin/statistician-management" class="nav-link">疾控中心统计员管理</RouterLink>
              <RouterLink to="/admin/system-config" class="nav-link">系统配置</RouterLink>
              <RouterLink to="/admin/profile" class="nav-link">个人中心</RouterLink>
            </template>
            
            <!-- 用户欢迎信息 -->
            <div class="user-welcome">
              <!-- 只在用户端和统计员端显示公告 -->
              <Notice v-if="userStore.isUser || userStore.isStatistician" />
              <span class="welcome-text">欢迎，{{ userStore.username }}</span>
              <button @click="userStore.logout()" class="logout-button">退出</button>
            </div>
          </template>
        </div>
      </nav>
    </header>
    
    <!-- 主内容区域 -->
    <main :class="['main-content', { 'full-screen-content': $route.path === '/statistician/health-data-dashboard' }]">
      <RouterView />
    </main>
    
    <!-- 使用Footer组件，仅在非登录/注册页面显示 -->
    <Footer v-if="$route.path !== '/login' && $route.path !== '/register' && $route.path !== '/statistician/health-data-dashboard'" />
  </div>
</template>

<style scoped>
.main-header {
  background: linear-gradient(135deg, #0072c6 0%, #005a9e 100%);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
}

.logo {
  font-size: 26px;
  font-weight: 700;
  color: #ffffff;
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: transform 0.3s ease;
}

.logo:hover {
  transform: scale(1.05);
}

.nav-links {
  display: flex;
  gap: 16px;
  align-items: center;
}

.nav-link {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 25px;
  transition: all 0.3s ease;
  background-color: rgba(255, 255, 255, 0.1);
}

.nav-link:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.nav-link.router-link-active {
  color: #005a9e;
  background-color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 用户欢迎信息样式 */
.user-welcome {
  display: flex;
  align-items: center;
  gap: 16px;
  background-color: rgba(255, 255, 255, 0.15);
  padding: 8px 16px;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.welcome-text {
  color: #ffffff;
  font-weight: 600;
  font-size: 15px;
}

.logout-button {
  background-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;
}

.logout-button:hover {
  background-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.main-content {
  flex: 1;
  width: 100%;
  min-height: calc(100vh - 120px); /* 减去导航栏高度 */
}

/* 全屏内容样式 - 用于可视化大屏 */
.full-screen-content {
  min-height: 100vh;
  height: 100vh;
  padding: 0;
  margin: 0;
  background-color: #050a14;
}
</style>

<style>
/* 全局重置样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f7fa;
  min-height: 100vh;
  min-width: 100vw;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  min-width: 100vw;
  display: flex;
  flex-direction: column;
}

.app-container {
  min-height: 100vh;
  min-width: 100vw;
  display: flex;
  flex-direction: column;
}

/* 确保所有页面容器都铺满屏幕 */
.page-container {
  min-height: 100vh;
  min-width: 100vw;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* 通用渐变背景类 - 医疗行业风格 */
.gradient-bg {
  background: linear-gradient(120deg, #1a91da 0%, #1164b2 50%, #0b4a8a 100%);
  position: relative;
  overflow: hidden;
}

/* 通用卡片样式 - 医疗行业风格 */
.app-card {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 40px;
  transition: all 0.3s ease;
}

.app-card:hover {
  box-shadow: 0 25px 65px rgba(0, 0, 0, 0.2);
  transform: translateY(-5px);
}

/* 通用按钮样式 - 医疗行业风格 */
.app-button {
  background: linear-gradient(135deg, #0072c6 0%, #005a9e 100%);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 6px 20px rgba(0, 114, 198, 0.3);
  position: relative;
  overflow: hidden;
}

.app-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(0, 114, 198, 0.4);
}

/* 通用输入框样式 */
.app-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid rgba(0, 114, 198, 0.2);
  border-radius: 12px;
  font-size: 16px;
  transition: all 0.3s ease;
  background-color: #fafdff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.app-input:focus {
  outline: none;
  border-color: #0072c6;
  box-shadow: 0 0 0 4px rgba(0, 114, 198, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.05);
  background-color: #ffffff;
}

/* 背景装饰元素通用类 */
.bg-decoration::before,
.bg-decoration::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  filter: blur(80px);
  z-index: 0;
}

.bg-decoration::before {
  width: 500px;
  height: 500px;
  top: -100px;
  left: -100px;
}

.bg-decoration::after {
  width: 600px;
  height: 600px;
  bottom: -200px;
  right: -200px;
}
</style>
